#include <iostream>
#include "StdTcpServer.h"
using namespace std;

StdTcpSocket client;
StdTcpServer server;
StdTcpSocketPrivate set;

void *thread_func(void *arg)
{
    client.connectToServer("192.168.248.128", 8888);
    char buffer[64];
    while (1)
    {
        char username[64];
        cout << "请输入用户名:";
        scanf("%s", username);

        char passwd[64];
        cout << "请输入密码:";
        scanf("%s", passwd);

        /* 创建一个json对象 */
        json_object *jsonObj = json_object_new_object();
        json_object_object_add(jsonObj, "type", json_object_new_int(1));
        json_object_object_add(jsonObj, "username", json_object_new_string(username));
        json_object_object_add(jsonObj, "passwd", json_object_new_string(passwd));

        /* 将json对象转换成字符串 */
        const char *jsonStr = json_object_to_json_string(jsonObj);

        /* 发送信息 */
        int length = strlen(jsonStr);
        cout << "length : " << length << endl;
        client.sendMessage((&length,));
    }
}

int main()
{

    pthread_t tid;
    pthread_create(&tid, NULL, thread_func, NULL);

    return 0;
}